package com.cloud.wms.ui.print.presenter;

import com.cloud.core.base.BaseRxPresenter;
import com.cloud.core.utils.MessageCreator;
import com.cloud.wms.app.FineExApplication;
import com.cloud.wms.http.Params;
import com.cloud.wms.http.observer.LoadingObserver;
import com.cloud.wms.http.observer.ResponseWrapper;
import com.cloud.wms.tools.RxUtils;
import com.cloud.wms.ui.print.contact.SelectBoxContact;
import com.cloud.wms.ui.print.entity.PrinterBoxEntity;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by FC on 2021/2/7.
 * Desc：
 */
public class SelectBoxPresenter extends BaseRxPresenter<SelectBoxContact.View> implements SelectBoxContact.Presenter {
    public static final int GET_BOX_MSG_SUCCESS = 0x100;

    @Inject
    public SelectBoxPresenter() {

    }

    @Override
    public void getBoxMsg(String boxCode) {
//        Observable.timer(500, TimeUnit.MILLISECONDS)
//                .map(new Function<Long, List<PrinterBoxEntity>>() {
//                    @Override
//                    public List<PrinterBoxEntity> apply(Long aLong) throws Exception {
//                        List<PrinterBoxEntity> boxEntityList = new ArrayList<>();
//                        for (int i = 0; i < 1; i++) {
//                            PrinterBoxEntity boxEntity = new PrinterBoxEntity();
////                            boxEntity.setBoxId(i + "");
//                            boxEntity.setBoxMark("xm" + boxCode);
//                            boxEntity.setBarCode("tm" + boxCode);
//                            boxEntity.setWarehouseMember("商业版CWMS测试仓 - 雪花秀官方旗舰店");
//                            boxEntity.setCommodityName("测试商品");
//                            boxEntity.setInCode("RK123456789");
////                            boxEntity.setAmount(100);
////                            boxEntity.setStockType(1);
//
//                            boxEntityList.add(boxEntity);
//                        }
//                        return boxEntityList;
//                    }
//                })
        Params params = Params.newInstance(Params.Type.WAREHOUSE);
        params.put("BoxCode", boxCode);
        FineExApplication.component().http().getBoxPrinterMsg(params)
                .map(new ResponseWrapper<>())
                .compose(mView.toLifecycle())
                .compose(RxUtils.threadSwitch())
                .subscribe(new LoadingObserver<List<PrinterBoxEntity>>(mView.provideContext()) {
                    @Override
                    public void onSuccess(List<PrinterBoxEntity> printerBoxEntities) {
                        mView.onSuccess(MessageCreator.createMessage(printerBoxEntities, GET_BOX_MSG_SUCCESS));
                    }

                    @Override
                    public void onError(String msg) {
                        mView.error(msg);
                    }
                });

    }
}
